AllWriterListPageManager=function(){
	this.inited=false;
	this.filterVM=null;
	this.writerListLoader=null;
}

AllWriterListPageManager.defValue={
	//shiciSearchContent:"#writer-search-content",
	filterPanelShowBtn:"#pop-filter-panel",
	filterWordsShow:"#filter-words-show",
	filterVMConfig:{
		el:"#filter-panel-content",
		data:{
			allAttrNames:["dynasty","name"],
			dynasty:"",
			name:""
		}
	},
	writerScrollConfig:{
	   el:"#xq-writer-result-scroll-wrapper",
	   up:{
		    initLoadOnce:true,
			loadFunction:function(manager){
				manager.loadWriterList();
			}
	   }
	},
	writerListLoaderConfig:{
		appVMConfig:{el:'#writer-result-list-ul'},
		itemContentEl:"#writer-result-list-ul",
		loadParam:{pageNo:1}
	}
}

AllWriterListPageManager.prototype.init=function(opts){
	var that=this;
	if(!this.inited){
		this.options=$.extend(true,{},AllWriterListPageManager.defValue,opts);
		//
		var $filterPanel=$(this.options.filterVMConfig.el);
		var panelH=$filterPanel.height()+1;
		$filterPanel.css('top',(0-panelH)+'px');
		//
		this.filterVM=new Vue(this.options.filterVMConfig);
		//
		this.writerListLoader=new WriterListLoader();
		this.options.writerListLoaderConfig.loadOverCallback=function(loader,data){
			that.writerScroll.loadOver(data.entry.hasNextPage);
		}
		this.writerListLoader.init(this.options.writerListLoaderConfig);
		//
		var writerScrollConfig=this.options.writerScrollConfig;
		var writerConfigUpFunction=writerScrollConfig.up.loadFunction;
		writerScrollConfig.up.loadFunction=function(){
			writerConfigUpFunction(that);
		}
		this.writerScroll=new RefreshAbleScroll(writerScrollConfig.el,writerScrollConfig);
		//this.writerScroll.resetUpEnabled({enabled:false,textShowStatus:'hidden'});
		//this.loadWriterList();
		//this.resetEleSize();
		this.registerEvent();
		
	}
	this.inited=true;
}


AllWriterListPageManager.prototype.loadWriterList=function(){
	var loadParam=this.writerListLoader.getLoadParam();
	//loadParam.tagId=this.tagId;
	this.writerListLoader.loadWriterList();
	loadParam.pageNo++;
}

AllWriterListPageManager.prototype.registerEvent=function(){
	var that=this;
	var shiciSearchContent=this.options.shiciSearchContent;
	// 搜索事件,获取搜索关键词
	this.registerFilterEvent();
}

//
AllWriterListPageManager.prototype.toogleFilterPopPanel=function(){
	var that=this;
	var maskEleId='filter-pop-panel-mask';
	var flagClass='poped-flag-class';
	var $filterPanel=$(this.options.filterVMConfig.el);
	var panelH=$filterPanel.height()+1;
	
	if($filterPanel.is('.'+flagClass)){
		$('#'+maskEleId).remove();
		$filterPanel.css('top',(0-panelH)+'px');
		$filterPanel.removeClass(flagClass);
	}else{
		$filterPanel.addClass(flagClass);
		$filterPanel.css('top',44+'px');
		setTimeout(function(){
			$filterPanel.find('input')[0].focus();
		},300);
		//
		if($('#'+maskEleId).length==0){
			var maskEle='<div class="xq-bg-mask" id="'+maskEleId+'"></div>';
			$('body').append($(maskEle));
			$('#'+maskEleId).css('z-index',8);
			$('#'+maskEleId).off('tap').on('tap',function(e){
				that.toogleFilterPopPanel();
			});
		}
	}
}
//
AllWriterListPageManager.prototype.registerFilterEvent=function(){
	var that=this;
	var $filterPanel=$(this.options.filterVMConfig.el);
	var filterPanelShowBtn=this.options.filterPanelShowBtn;
	//
	$(filterPanelShowBtn).on('tap',function(e){
		that.toogleFilterPopPanel();
	});
	//
	$($filterPanel).find('input').on('keyup',function(e){
		if(e.keyCode == 13) {//用户点击回车的事件号为13
			that.doFilterWriterList();
			that.toogleFilterPopPanel();
		}
	});
	//
	$($filterPanel).find(".func-confirm-btn").on('tap',function(e){
		that.doFilterWriterList();
		that.toogleFilterPopPanel();
	});
	//
	$($filterPanel).find(".func-cancel-btn").on('tap',function(e){
		that.toogleFilterPopPanel();
	});
}
//
AllWriterListPageManager.prototype.doFilterWriterList=function(){
	document.activeElement.blur();//收起虚拟键盘
	var $filterPanel=$(this.options.filterVMConfig.el);
	
	//
	var writerLoadParam=this.writerListLoader.getLoadParam();
	writerLoadParam.pageNo=1;

	var allAttrNames=this.filterVM.allAttrNames;
	var filterWords='';
	for(var i=0;i<allAttrNames.length;i++){
		var tmpElem=allAttrNames[i];
		var name=tmpElem;
		var value=this.filterVM[name];
		writerLoadParam[name]=value;
		if(value){
			filterWords+=value+' ';
		}
	}
	var filterWordsShow=this.options.filterWordsShow;
	$(filterWordsShow).html(filterWords);
	this.writerListLoader.emptyWriterList();
	this.writerScroll.reInit();
}